package com.cy.store.service.impl;

import com.cy.store.entity.District;
import com.cy.store.repository.DistrictRepository;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistrictServiceImpl implements IDistrictService {
    @Autowired
    private DistrictRepository districtRepository;

    @Override
    public List<District> getByParent(String parent) {
        //优化，将无效数据设置成null，以便传输过程中减少流量
        List<District>  districtListst = districtRepository.findAllByParentOrderByCodeAsc(parent);
        for(District x: districtListst){
            x.setId(null);
            x.setParent(null);
        }
        return districtListst;
    }

    @Override
    public String getNameByCode(String code) {
        return districtRepository.findNameByCode(code);
    }
}
